
//
//  BaseViewModel.swift
//  DouYuZB
//
//  Created by wangpeng on 2017/2/25.
//  Copyright © 2017年 鼎商动力. All rights reserved.
//

import UIKit

class BaseViewModel: NSObject {
    lazy  var anchorGroup:[AnchorGroup] = [AnchorGroup]()
}

extension BaseViewModel{
    func loadAnchorData(isGroupdata: Bool, URL: String, parameters: [String: Any]? = nil, finishedcalllback:@escaping()->()){
        NetworkTools.requestData(.get, URLString: URL,parameters: parameters) { (request) in
            //1.对界面进行处理
            guard let requestdict = request as? [String : Any],
                let dataArray = requestdict["data"] as? [[String : Any]]
                else { return }
            //2.遍历数组中的字典
            if(isGroupdata){
                //2.1遍历数组中的字典
                for dict in dataArray{
                    self.anchorGroup.append(AnchorGroup(dict:dict))
                }
            }else{
                let group = AnchorGroup()
                for dict in dataArray{
                    group.anchors.append(AnchorModel(dict:dict))
                }
                self.anchorGroup.append(group)
            }
            //3.完成回调
            finishedcalllback()
        }
    }
}
